﻿using MesErreurs;
using Metier;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Gestion_commerciale
{
    public partial class FModif_Art : Form
    {
        Article article;

        public FModif_Art(string numArticle)
        {
            InitializeComponent();
            bNumCom.Text = numArticle;
            article = new Article();
            try
            {
                article.RechercheUnArticle(numArticle);
            }
            catch (MonException exception)
            {
                MessageBox.Show(exception.MessageApplication(), exception.Message);
            }

            CLibArt.Text = article.LibArticle;
            CQteDispo.Text = article.QteDispo.ToString();
            CPrix.Text = article.PrixArticle.ToString();
            CVille.Text = article.VilleArticle;
            if (article.Interrompu == "F") bNon.Checked = true;
            else bOui.Checked = true;
        }

        private void CNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }

        private void bModifier_Click(object sender, EventArgs e)
        {
            double number;
            if (CPrix.Text == "" || !Double.TryParse(CPrix.Text, out number))
            {
                MessageBox.Show("Entrez un prix au bon format");
            }
            else
            {
                number = Math.Round(number, 2);
                CPrix.Text = number.ToString();
                if (bOui.Checked == true) article.Interrompu = "T";
                else article.Interrompu = "F";
                article.LibArticle = CLibArt.Text;
                article.QteDispo = Convert.ToInt32(CQteDispo.Text);
                article.PrixArticle = Convert.ToSingle(CPrix.Text);
                article.VilleArticle = CVille.Text;

                article.modifierArticle();
                Close();
            }
        }
    }
}
